package leetcode;

import org.junit.Test;

/**
 * @author Liangyaoyun
 */
public class MyBinarySearch {
    public int BinarySearch(int[] nums,int target,int start,int end){
        int len=nums.length-1;
        int mid=start+(end-start)/2;
        if(start>end){
            return -start-1;
        }
        if (target>nums[mid]){
            return BinarySearch(nums,target,mid+1,end);
        }else if (target<nums[mid]){
            return BinarySearch(nums,target,start,mid-1);
        }else if(target==nums[mid]){
            return mid;
        }

        return -1;
    }
    @Test
    public  void main() {
        int[] nums=new int[]{-1,0,3,5,9,12};
        int target=13;
        int start=0;
        int end=nums.length-1;
        System.out.println(BinarySearch(nums, target, start, end));
    }
}
